<template>
    <div class='list' ref='wrapper'>
      <div>
        <div class="area">
          <div class='title border-topbottom'>您的城市</div>
          <div class='button-list'>
            <div class='button-wrapper'>
              <div class='button'>{{this.$store.state.city}}</div>
            </div>
          </div>
        </div>
        <div class="area">
          <div class='title border-topbottom'>热门城市</div>
          <div class='button-list'>
            <div class="button-wrapper"
              v-for='item of hot'
              :key='item.id'
              @click='handCityClick(item.name)'
            >
              <div class="button">{{item.name}}</div>
            </div>
          </div>
        </div>
        <div
          class="area"
          v-for='(item,key) of cities'
          :key='key'
          :ref='key'
        >
          <div class='title border-topbottom'>{{key}}</div>
          <div class="item-list">
            <div class='border-bottom' v-for='innerItem of item' :key='innerItem.id' @click='handCityClick(innerItem.name)'>{{innerItem.name}}</div>
          </div>
        </div>
      </div>
    </div>

</template>

<script>
import BScroll from 'better-scroll'
// import {mapState} from 'vuex'
export default {
  name: 'CityList',
  props: {
    cities: Object,
    hot: Array,
    letter: String
  },
  // computed: {
  //   ...mapState({
  //     currentCity: 'city'
  //   })
  // },
  methods: {
    handCityClick (city) {
      this.$store.dispatch('changeCity', city)
      this.$router.push('./')
    }
  },
  watch: {
    letter () {
      // console.log(this.letter)
      if (this.letter) {
        const element = this.$refs[this.letter][0]
        console.log(element)
        this.scroll.scrollToElement(element)
      }
    }
  },
  mounted () {
    // console.log(this.cities)
    this.scroll = new BScroll(this.$refs.wrapper)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .border-topbottom
    &:before
      border-color: #ccc
    &:after
      border-color: #ccc
  .list
    overflow: hidden
    top: 1.6rem
    left: 0
    position: absolute
    right: 0
    bottom: 0
    .title
      padding-left: .2rem
      background: #eef
      line-height:.44rem
      color: #666
      font-size: .26rem
    .button-list
      // width: 100%
      padding:.1rem
      overflow: hidden
      // box-sizing: border-box
      .button-wrapper
        width: 30%
        padding: .03rem
        float: left
        box-sizing: border-box
        .button
          border: .01rem solid #c6c7c7
          padding: .02rem
          margin: .1rem
          font-size: #4e5362
          color: #666
          text-align: center
          border-radius: .05rem
    .item-list
      // width:70%
      padding:.02rem
      font-size: .2rem
      padding: .2rem
      color: #666
      line-height: .7rem
    .border-bottom
      &:before
        border-color: #ccc
</style>
